﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QControlCenter.ViewModel
{
    public class QBaseVM: ObservableObject
	{
		public  void UpdateFrom< F>(F info)
		{
			if (info == null) return;
			var f_propertys = info.GetType().GetProperties();
			var t_propertys = this.GetType().GetProperties();

			for (int i = 0; i < t_propertys.Length; i++)
			{
				var tt = info.GetType().GetProperty(t_propertys[i].Name);
				if (tt == null) continue;
				var tt_val = tt.GetValue(info);
				if (tt_val == null) continue;
				
				t_propertys[i].SetValue(this, tt_val);
				

			}
		}

		public void UpdateTo<T>(T info)
		{
			if (info == null) return;
			var f_propertys = info.GetType().GetProperties();
			var t_propertys = typeof(T).GetProperties();
			for (int i = 0; i < f_propertys.Length; i++)
			{
				var tt = this.GetType().GetProperty(f_propertys[i].Name);
				if (tt == null) continue;
				var tt_val = tt.GetValue(this);
				if (tt_val == null) continue;
				 
				f_propertys[i].SetValue(info, tt_val);

			}
		}


	}
}
